/* ----------------------------------------------------------------------------

	pax.plugin.widget.video.js Copyright (C) 2008 Mikkel Bergmann, Pointful

	Licence
	-------
	
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

	See lgpl.txt for licence details

---------------------------------------------------------------------------- */
/*
	Script: pax.plugin.widget.video
		This plugin for PAX allows you to easily embed videos
		
	Author:
		Mikkel Bergmann, <http://www.pointful.com>

	License:
		GNU General Public License.

	Comments:

*/

var pax = pax || {};
pax.plugin = pax.plugin || {};
pax.plugin.widget = pax.plugin.widget || {};
pax.plugin.widget.video = pax.plugin.widget.video || {};

pax.plugin.widget.video.embedStrings = {
	'youtube.com': function( url ) {
		var params = pax.postParams( url );
		return '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/' + params['v'] + '&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/' + params['v'] + '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
	},
	'video.google.com': function( url ) {
		var params = pax.postParams( url );
		return '<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=' + params['docid'] + '" flashvars=""></embed>';
	},
	'collegehumor.com': function( url ) {
		var param = url.substring( url.indexOf( 'video:' ) + 6 );
		return '<object type="application/x-shockwave-flash" data="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=' + param + '&fullscreen=1" width="480" height="360" ><param name="allowfullscreen" value="true" /><param name="movie" quality="best" value="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=' + param + '&fullscreen=1" /></object>';
	},
	'metacafe.com': function( url ) {
		var param = url.substring( url.indexOf( 'watch/' ) + 6, url.length - 1 );
		return '<embed src="http://www.metacafe.com/fplayer/' + param + '.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> </embed>';
	},
	'livevideo.com': function( url ) {
		var params = pax.postParams( url );
		if( url.indexOf( 'cid' ) == -1 ) {
			var parts = url.split( '/' );
			params = { cid: parts[ parts.length - 2 ] };
		}
		return '<embed src="http://www.livevideo.com/flvplayer/embed/' + params['cid'] + '" type="application/x-shockwave-flash" quality="high" WIDTH="445" HEIGHT="369" wmode="transparent"></embed>';
	},
	'liveleak.com': function( url ) {
		var params = pax.postParams( url );
		return '<object type="application/x-shockwave-flash" width="450" height="370" wmode="transparent" data="http://www.liveleak.com/player.swf?autostart=false&token=' + params['i'] + '"><param name="movie" value="http://www.liveleak.com/player.swf?autostart=false&token=' + params['i'] + '"><param name="wmode" value="transparent"><param name="quality" value="high"></object>'
	}
};
	

pax.plugin.widget.video.init = function( element, args ) {
	element = pax.$( element );
	args.url = ( args.url == null )? '': args.url;

	for( var i in pax.plugin.widget.video.embedStrings ) {
		if( args.url.indexOf( i ) != -1 ) {		
			var paramUrl = args.url.substring( args.url.indexOf('?') + 1 );	//	We strip the off the part before the first "?"
			element.innerHTML = pax.plugin.widget.video.embedStrings[i]( paramUrl );	//['embed'].split("__v__").join( "Rjpn3L3bSJQ" );
		}
	}

};